package com.example.qu_tao.View;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.qu_tao.Util.CaiGouDataManager;
import com.example.qu_tao.adapter.CaiGouAdapter;
import com.example.qu_tao.entity.CaiGouInfo;
import com.example.qu_tao.R;
import java.util.List;

public class CaiGouXinXiFragment extends Fragment {

    private RecyclerView recyclerView;
    private CaiGouAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 加载采购信息的布局
        View view = inflater.inflate(R.layout.fragment_caigouxinxi, container, false);
        recyclerView = view.findViewById(R.id.recycler_view_caigou);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 获取采购信息列表
        List<CaiGouInfo> caiGouInfoList = CaiGouDataManager.getInstance().getAllCaiGouInfo();
        adapter = new CaiGouAdapter(caiGouInfoList);
        recyclerView.setAdapter(adapter);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        // 更新数据
        List<CaiGouInfo> caiGouInfoList = CaiGouDataManager.getInstance().getAllCaiGouInfo();
        adapter.updateData(caiGouInfoList);
    }
}